import { Transform, Type } from "class-transformer";
import { IsOptional, IsString, IsInt, ValidateNested, IsNumber } from "class-validator";
import { PartialType } from "@nestjs/mapped-types";
import { BaseQueryDto } from "../base.dto";
import { ApiProperty } from "@nestjs/swagger";

export class MediaAddDto {
    @ApiProperty({ description: "媒体标题, 文件名" })
    @IsString()
    title: string;

    @ApiProperty({ description: "文件路径" })
    @IsString()
    filepath: string;

    @ApiProperty({ description: "媒体时长" })
    @IsNumber()
    duration: number;

    @ApiProperty({ description: "已播放时长" })
    @IsNumber()
    lastPosition: number;
}

class MediaQueryWhereDto {
    @ApiProperty({ description: "文件路径" })
    @IsString()
    @IsOptional()
    filepath?: string;
}

export class MediaQueryDto extends BaseQueryDto {
    @ApiProperty({ type: MediaQueryWhereDto, description: "查找规则" })
    @ValidateNested()
    @Type(() => MediaQueryWhereDto)
    @IsOptional()
    where?: MediaQueryWhereDto;
}

export class MediaRemoveDto {
    @ApiProperty({ description: "数据库id" })
    @IsInt()
    @Transform(({ value }) => parseInt(value))
    id: number;
}

export class MediaUpdateDto extends PartialType(MediaAddDto) {
    @ApiProperty({ description: "数据库id" })
    @IsInt()
    @Transform(({ value }) => parseInt(value))
    id: number;
}
